## The following line supports click-mkmindriver and should not be changed.
## Click userlevel driver Makefile ##
SHELL = @SHELL@

top_srcdir := @top_srcdir@
srcdir := @srcdir@
top_builddir := ..
subdir := userlevel
conf_auxdir := @conf_auxdir@

prefix = @prefix@
bindir = @bindir@
sbindir = @sbindir@
libdir = @libdir@

VPATH = .:$(top_srcdir)/lib:$(top_srcdir)/$(subdir):$(top_srcdir)/elements/standard

CC = @CC@
CPP = @CPP@
CXX = @CXX@
CXXCPP = @CXXCPP@
DEPCFLAGS = @DEPCFLAGS@
AR_CREATE = @AR@ @AR_CREATEFLAGS@
RANLIB = @RANLIB@
INSTALL = @INSTALL@
mkinstalldirs = $(conf_auxdir)/mkinstalldirs

CLICK_BUILDTOOL = $(top_builddir)/bin/click-buildtool

ifeq ($(V),1)
ccompile = $(COMPILE) $(DEPCFLAGS) $(1)
ccompile_nodep = $(COMPILE) $(1)
cxxcompile = $(CXXCOMPILE) $(DEPCFLAGS) $(1)
cxxcompile_nodep = $(CXXCOMPILE) $(1)
cxxlink = $(CXXLINK) $(1)
x_verbose_cmd = $(1) $(3)
verbose_cmd = $(1) $(3)
else
ccompile = @/bin/echo ' ' $(2) $< && $(COMPILE) $(DEPCFLAGS) $(1)
ccompile_nodep = @/bin/echo ' ' $(2) $< && $(COMPILE) $(1)
cxxcompile = @/bin/echo ' ' $(2) $< && $(CXXCOMPILE) $(DEPCFLAGS) $(1)
cxxcompile_nodep = @/bin/echo ' ' $(2) $< && $(CXXCOMPILE) $(1)
cxxlink = @/bin/echo ' ' $(2) $@ && $(CXXLINK) $(1)
x_verbose_cmd = $(if $(2),/bin/echo ' ' $(2) $(3) &&,) $(1) $(3)
verbose_cmd = @$(x_verbose_cmd)
endif

.SUFFIXES:
.SUFFIXES: .S .c .cc .o .s .ii

.c.o:
	$(call ccompile,-c $< -o $@,CC)
.s.o:
	$(call ccompile,-c $< -o $@,ASM)
.S.o:
	$(call ccompile,-c $< -o $@,ASM)
.cc.o:
	$(call cxxcompile,-c $< -o $@,CXX)
.cc.s:
	$(call cxxcompile_nodep,-S $< -o $@,CXX -S)
.cc.ii:
	$(call cxxcompile_nodep,-E $< > $@,CXXCPP)


GENERIC_OBJS = string.o straccum.o nameinfo.o \
	bitvector.o bighashmap_arena.o hashallocator.o \
	ipaddress.o ipflowid.o etheraddress.o \
	packet.o \
	error.o timestamp.o glue.o task.o timer.o atomic.o fromfile.o gaprate.o \
	element.o \
	confparse.o args.o variableenv.o lexer.o elemfilter.o routervisitor.o \
	routerthread.o router.o master.o timerset.o selectset.o handlercall.o notifier.o \
	integers.o md5.o crc32.o in_cksum.o iptable.o \
	archive.o userutils.o driver.o \
	$(EXTRA_DRIVER_OBJS)

EXTRA_DRIVER_OBJS = @EXTRA_DRIVER_OBJS@

LIBOBJS = $(GENERIC_OBJS) $(STD_ELEMENT_OBJS) clp.o exportstub.o
STD_ELEMENT_OBJS = addressinfo.o alignmentinfo.o \
	errorelement.o portinfo.o scheduleinfo.o
OBJS = $(ELEMENT_OBJS) $(ELEMENTSCONF).o click.o

CPPFLAGS = @CPPFLAGS@ -DCLICK_USERLEVEL
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@

DEFS = @DEFS@
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
	-I$(srcdir) -I$(top_srcdir) \
	@PROPER_INCLUDES@ @PCAP_INCLUDES@ @DPDK_INCLUDES@ @NETMAP_INCLUDES@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@ `$(CLICK_BUILDTOOL) --otherlibs` $(ELEMENT_LIBS)
DL_LDFLAGS = @DL_LDFLAGS@

CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(CXXFLAGS) $(LDFLAGS) -o $@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@

USE_DPDK = @USE_DPDK@
ifeq ($(USE_DPDK),yes)
RTE_SDK = @RTE_SDK@
RTE_TARGET = @RTE_TARGET@
RTE_VER_MAJOR = @RTE_VER_MAJOR@
RTE_VER_MINOR = @RTE_VER_MINOR@
RTE_VER_YEAR = @RTE_VER_YEAR@
RTE_VER_MONTH = @RTE_VER_MONTH@
include dpdk.mk
EXTRA_DRIVER_OBJS := dpdkdevice.o $(EXTRA_DRIVER_OBJS)
endif

ifndef MINDRIVER
DRIVER = click
ELEMENTSCONF = elements
INSTALLLIBS = libclick.a
FINDELEMFLAGS = @FINDELEMFLAGS@ --checksum elements.csmk
-include elements.csmk
else
DRIVER = $(MINDRIVER)click
ELEMENTSCONF = elements_$(MINDRIVER)
endif
INSTALLPROGS = $(DRIVER)

ifneq ($(ELEMENT_CHECKSUM),)
ifneq ($(shell $(ELEMENT_CHECKSUMCOMMAND)),$(ELEMENT_CHECKSUM))
$(shell rm -f $(ELEMENTSCONF).conf $(ELEMENTSCONF).csmk)
endif
endif


all: $(INSTALLPROGS) $(INSTALLLIBS)

ifneq ($(MAKECMDGOALS),clean)
-include $(ELEMENTSCONF).mk
endif

$(DRIVER): Makefile libclick.a $(OBJS)
	$(call cxxlink,$(DL_LDFLAGS) $(OBJS) libclick.a $(LIBS),LINK)
	@-mkdir -p ../bin; rm -f ../bin/$@; ln -s ../userlevel/$@ ../bin/$@

libclick.a: Makefile $(LIBOBJS)
	$(call verbose_cmd,$(AR_CREATE) libclick.a $(LIBOBJS),AR libclick.a)
	$(call verbose_cmd,$(RANLIB),RANLIB,libclick.a)

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@

elemlist:
	@rm -f elements.conf elements.csmk
	@$(MAKE) elements.conf
elements.conf: $(top_builddir)/config.status $(CLICK_BUILDTOOL)
	$(call verbose_cmd,echo "userlevel @element_groups@" | $(CLICK_BUILDTOOL) findelem -r userlevel -p $(top_srcdir) -X $(srcdir)/elements.exclude $(FINDELEMFLAGS) >,FINDELEMENTS,elements.conf)
$(ELEMENTSCONF).mk: $(ELEMENTSCONF).conf $(CLICK_BUILDTOOL)
	$(call verbose_cmd,$(CLICK_BUILDTOOL) elem2make -x "$(STD_ELEMENT_OBJS)" < $(ELEMENTSCONF).conf >,CREATE,$(ELEMENTSCONF).mk)
$(ELEMENTSCONF).cc: $(ELEMENTSCONF).conf $(CLICK_BUILDTOOL)
	$(call verbose_cmd,$(CLICK_BUILDTOOL) elem2export < $(ELEMENTSCONF).conf >,CREATE,$(ELEMENTSCONF).cc)
	@rm -f $(ELEMENTSCONF).d

DEPFILES := $(wildcard *.d)
ifneq ($(DEPFILES),)
include $(DEPFILES)
endif

install: $(INSTALLPROGS) install-lib
	$(call verbose_cmd,$(mkinstalldirs) $(DESTDIR)$(bindir))
	@for i in $(INSTALLPROGS); do $(call x_verbose_cmd,$(INSTALL) $$i,INSTALL,$(DESTDIR)$(bindir)/$$i); done
install-include:
	@:
install-lib: $(INSTALLLIBS)
	$(call verbose_cmd,$(mkinstalldirs) $(DESTDIR)$(libdir))
	@for i in $(INSTALLLIBS); do $(call x_verbose_cmd,$(INSTALL) $$i,INSTALL,$(DESTDIR)$(libdir)/$$i); done
install-man:
	@:
uninstall:
	for i in $(INSTALLLIBS); do rm -f $(DESTDIR)$(libdir)/$$i; done
	for i in $(INSTALLPROGS); do rm -f $(DESTDIR)$(bindir)/$$i; done

clean:
	rm -f *.d *.o $(INSTALLPROGS) $(ELEMENTSCONF).mk $(ELEMENTSCONF).cc elements.conf elements.csmk libclick.a
	@-for i in $(INSTALLPROGS); do rm -f ../bin/$$i; done
clean-lib:
	rm -f $(LIBOBJS) libclick.a
distclean: clean
	-rm -f Makefile

.PHONY: all clean clean-lib distclean elemlist \
	install install-include install-lib install-man uninstall
